﻿using DevExpress.ExpressApp.DC;
using DevExpress.Persistent.Base;
using System.ComponentModel;

namespace EasyXaf.EntityDesigner.Tools.Extensions;

public static class BaseInfoExtensions
{
    public static string GetCaption(this IBaseInfo baseInfo)
    {
        var attribute1 = baseInfo.FindAttribute<DisplayNameAttribute>(false);
        if (attribute1 != null)
        {
            return attribute1.DisplayName;
        }

        var attribute2 = baseInfo.FindAttribute<DevExpress.Xpo.DisplayNameAttribute>(false);
        if (attribute2 != null)
        {
            return attribute2.DisplayName;
        }

        var attribute3 = baseInfo.FindAttribute<XafDisplayNameAttribute>(false);
        if (attribute3 != null)
        {
            return attribute3.DisplayName;
        }

        return null;
    }

    public static string GetDescription(this IBaseInfo baseInfo)
    {
        return baseInfo.FindAttribute<DescriptionAttribute>(false)?.Description;
    }

    public static string GetImageName(this IBaseInfo baseInfo)
    {
        return baseInfo.FindAttribute<ImageNameAttribute>(false)?.ImageName;
    }
}
